<template>
	<yd-layout id='myHeart' class=''>
		<div class="nav" v-if='false'>
			<div @click='navNum=1'  :class="navNum==1?'nav_avtive':''" class="nav_list">
				<div class="nav_name">发出的</div>
				<span></span>
			</div>
			<div @click='navNum=2'  :class="navNum==2?'nav_avtive':''" class="nav_list">
				<div class="nav_name">收到的</div>
				<span></span>
			</div>
		</div>
		<div class="content" >
			<div v-show="navNum==1&&false" class="send">
				<yd-infinitescroll  v-show="sendList.length>0"  :callback="getSendList" ref="infinitescrollDemo">
						<div  slot="list"  class="heart_list" v-for="item in sendList" @click="goMyHeartDetail(item,1)"> 
							<div class="list_header">
								<div class="list_come">致：{{item.nick_name}}</div>
								<div class="list_time">{{item.newTime}}</div>
							</div>
							<div class="list_content">{{item.content}}</div>
						</div>
						<!-- 数据全部加载完毕显示 -->
						<span slot="doneTip">没有更多数据了~~</span>
		
						<!-- 加载中提示，不指定，将显示默认加载中图标 -->
						<!--<img slot="loadingTip" src="path/img/loading.svg"/>-->
				</yd-infinitescroll>
			</div>
			<!--sendList.length==0&&navNum==1-->
			<NoList v-show='true'>
				<img slot='img' src="../../assets/kong_1.png" alt="" />
			</NoList>
			<div v-show="navNum==2&&false"  class="receive">
					<yd-infinitescroll v-show="reciveList.length>0" :callback="getReciveList" ref="infinitescrollDemoRecive">
						<div  slot="list"  class="heart_list" v-for="item in reciveList" @click="goMyHeartDetail(item,2)"> 
							<div class="list_header">
								<div class="list_come">来自：{{item.nick_name}}</div>
								<div class="list_time">{{item.newTime}}</div>
							</div>
							<div class="list_content">{{item.content}}</div>
						</div>
						<!-- 数据全部加载完毕显示 -->
						<span slot="doneTip">没有更多数据了~~</span>
		
						<!-- 加载中提示，不指定，将显示默认加载中图标 -->
						<!--<img slot="loadingTip" src="path/img/loading.svg"/>-->
					</yd-infinitescroll>
					
			</div>
			<NoList v-show='reciveList.length==0&&navNum==2&&false'>
				<img slot='img' src="../../assets/kong_1.png" alt="" />
			</NoList>
		</div>
		<yd-backtop></yd-backtop>
	</yd-layout>
</template>

<script>
	import { InfiniteScroll } from 'vue-ydui/dist/lib.rem/infinitescroll';
	import { BackTop } from 'vue-ydui/dist/lib.rem/backtop';
	export default{
		components:{
			[InfiniteScroll.name]: InfiniteScroll,
			[BackTop.name]: BackTop,
		},
		data(){
			return {
				navNum:1,
				pageNum_recive:1,
				reciveList:[],
				pageCount:10,
				pageNum_send:1,
				sendList:[],
			}
		},
		created() {
		},
		watch: {
			
		},
		computed: {
			
		},
		mounted(){
			document.title='我的心声'
//			this.getSendList()
//			this.getReciveList()
		},
		methods:{
			getReciveList(){
				this.$root.ajax({
					name: 'heart/recv',
					type:'get',
					params: {
						page: this.pageNum_recive,
						count: this.pageCount,
						uid:this.$route.query.uid
					}
				}).then((d) => {
					for(let a = 0; a < d.data.comment_list.length; a++) {
						d.data.comment_list[a].newTime = this.$root.getDate(new Date(d.data.comment_list[a].create_time * 1000))
					}
					this.reciveList = [...this.reciveList, ...d.data.comment_list];
					if(this.reciveList.length >= d.data.comment_total) {
						/* 所有数据加载完毕 */
						this.$refs.infinitescrollDemoRecive.$emit('ydui.infinitescroll.loadedDone');
						return;
					}

					/* 单次请求数据完毕 */
					this.$refs.infinitescrollDemoRecive.$emit('ydui.infinitescroll.finishLoad');

					this.pageNum_recive++;
				})
			},
			getSendList(){
				this.$root.ajax({
					name: 'heart/send',
					type:'get',
					params: {
						page: this.pageNum_send,
						count: this.pageCount,
						uid:this.$route.query.uid
					}
				}).then((d) => {
					for(let a = 0; a < d.data.comment_list.length; a++) {
						d.data.comment_list[a].newTime = this.$root.getDate(new Date(d.data.comment_list[a].create_time * 1000))
					}
					this.sendList = [...this.sendList, ...d.data.comment_list];
					if(this.sendList.length >= d.data.comment_total) {
						/* 所有数据加载完毕 */
						this.$refs.infinitescrollDemo.$emit('ydui.infinitescroll.loadedDone');
						return;
					}

					/* 单次请求数据完毕 */
					this.$refs.infinitescrollDemo.$emit('ydui.infinitescroll.finishLoad');

					this.pageNum_send++;
				})
			},
			goMyHeartDetail(item,num){
				item.num = num 
				sessionStorage.setItem('wst_myHeart',JSON.stringify(item))
				this.$router.push({
					name:'myHeartDetail'
				})
			}
		}
	}
</script>

<style lang="scss">
	@import './myHeart.scss';
</style>